package cn.edu.gdpt.mobile0123456789lu0503;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class MyDataAdapter {
    MySQLiteOpenHelper openHelper=null;
    SQLiteDatabase database;
    public void openDB(Context context){
        openHelper=new MySQLiteOpenHelper(context,"student.db",null,1);
        try{
           database=openHelper.getWritableDatabase();
        }catch (Exception e){
            database=openHelper.getReadableDatabase();
        }
    }
    public void closeDB(){
        if(database!=null){
            database.close();
            database=null;
        }
        if(openHelper!=null){
            openHelper.close();
            openHelper=null;
        }
    }
    public boolean isOpen(){
        if(database!=null){
            return database.isOpen();
        }else
            return false;
    }
    public  boolean isReadOnly() {
        if (database != null) {
            return database.isReadOnly();
        } else
            return false;
    }
    public int getVersion(){
        if (database != null) {
            return database.getVersion();
        } else
        return -1;
    }
    public String getPath(){
        if(database!=null){
            return database.getPath();
        }else
            return "数据库为打开";
    }
}
